package com.blueearth.xingepush;

import com.blueearth.xingepush.PushHubProxy;

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * This class echoes a string called from JavaScript.
 */
public class XingePush extends CordovaPlugin {

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (action.equals("startRegPush")) {
            String message = args.getString(0);
            this.startRegPush(message, callbackContext);
            return true;
        }
        return false;
    }

    private void startRegPush(String userId, CallbackContext callbackContext) {
        if (userId != null && userId.length() > 0) {
//            callbackContext.success(message);
          PushHubProxy pushHubProxy = new PushHubProxy(cordova.getActivity());
          pushHubProxy.startRegisterPush(userId);
        } else {
            callbackContext.error("推送id绑定失败");
        }
    }
}
